#pragma once;

#include <windows.h>
#include <string>
#include <iostream>

using namespace std;

string str_replace(string text, string tag, string replacement)
{
    string res = text;
    size_t pos = 0;
    while((pos = res.find(tag, pos)) != std::string::npos)
	{
		res.replace(pos, tag.length(), replacement);
		pos += replacement.length();
	}
    return res;
}

BOOL GetLastWriteTime(const char *szBuf, FILETIME &ftWrite, BOOL directory)
{
    FILETIME ftCreate, ftAccess;
	HANDLE hFile;
	DWORD dwFlagsAndAttributes=0;
	if(directory == TRUE)
		dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS;
    
    hFile = CreateFile(szBuf, 0/*GENERIC_READ*/, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
	if(hFile == INVALID_HANDLE_VALUE)
    {
		cerr<<"\n"<<"CreateFile failed. Error: "<<GetLastError()<<", File: "<<szBuf;
		return FALSE;
	}
    // Retrieve the file times for the file.
    if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
    {
		cerr<<"\n"<<"GetFileTime failed. Error: "<<GetLastError()<<", File: "<<szBuf;
		return FALSE;    
	}
	CloseHandle(hFile);  
    return TRUE;
}